package com.xk.app_home.viewmodel

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope

import com.example.common.BannerData
import com.example.common.NetlibXK

import com.example.common.Result
import com.example.repo.RespStateData
import com.example.viewmodel.BaseVideModel
import com.kongzue.dialogx.dialogs.TipDialog
import com.xk.app_home.api.HomeApi
import com.xk.app_home.data.Article

import com.xk.app_home.data.Banner
import com.xk.app_home.repo.HomeRepo
import kotlinx.coroutines.launch

class HomeFragmentVM() : ViewModel() {

    private val  _dataResult = MutableLiveData<Article>()
    val dataResult: LiveData<Article> = _dataResult
    private val _bannerResult = MutableLiveData<List<Banner>>()
    val bannerResult: LiveData<List<Banner>> = _bannerResult
    var currentPage:Int = 0
    private var listdata : com.example.common.Result.DataDTO? = null

    //new
    var bannerList = RespStateData<List<Banner>>()
    public fun getBanner(){
        viewModelScope.launch {
            val  result = NetlibXK.getInstance().retrofit.create(HomeApi::class.java).getBanner()
            if(result.errorCode==0){
                    _bannerResult.value = result.data
            }else{
                    TipDialog.show(result.errorMsg)
            }
        }
    }


    public fun getArticle(page:Int,size:Int){
        viewModelScope.launch {
            val result = NetlibXK.getInstance().retrofit.create(HomeApi::class.java).getArticleList(page,size)
            if(result.errorCode==0){
                _dataResult.value = result.data
            }else{
                TipDialog.show(result.errorMsg)
            }
        }
    }
}